import java.util.Map;

/**
 * he class Variable for ex. 10. A Variable is represented by its name.
 *  The values of all the variables are held in a Map. 
 * @author Daniel Shalev
 *
 */
public class Variable implements Expression {
	private String variable;
	/**
	 * Constructor that builds a Variable object. Variable name is given in variable name. 
	 * @param variableName the name of the variable.
	 */
	public Variable(String variableName){
		variable=variableName;
	}
	
	/**
	 * Returns the value of the variable. Variables' values are as given in env. 
	 * @param env The Map giving for each variable name its value. 
	 * @return     the value of the variable if it has a value assigned in env, Double.NaN otherwise.
	 */
	public double eval(Map<String, Double> env) {
		//checks if the map is not null and if it has the variable it returns it value
		if(env!=null && env.containsKey(variable)){
			return env.get(variable);
		}
		else
			return Double.NaN;
	}
	
	/**
	 * String representation of the variable name. 
	 * @param order the operator order used to build the String.
	 * @return     the variable name (regardless of the order). 
	 */
	public String toString(OpOrder order) {
		return variable;
	}

}
